<?php
namespace app\index\controller;

use \think\facade\Db;
use \think\facade\View;
use \think\facade\Request;


class goods{
    public function goodList()
    {
        $where=[];
        $show=Request::param("is_show");
        $hot=Request::param("is_hot");
        $down=Request::param("is_down");
        $cid=Request::param("cid");
        $keywords=Request::param("keywords");
        $time1=Request::param('time1');
        $time=Request::param('time');
        $price=Request::param('price');
        $price1=Request::param('price1');
        View::assign('keywords',$keywords);
        View::assign('is_show',$show);
        View::assign('is_hot',$hot);
        View::assign('is_down',$down);
        View::assign('time',$time);
        View::assign('time1',$time1);
        View::assign('price',$price);
        View::assign('price1',$price1);
        if ($show<>''&&isset($show)) $where['is_show']=$show;
        if ($hot<>''&&isset($hot)) $where['is_hot']=$hot;
        if ($down==1&&isset($down)) $where['is_down']=$down[0];
        if ($cid<>''&&isset($cid)) $where['cid']=$cid;
        if ($keywords<>''&&isset($keywords)) $where['keywords']=$keywords;
        if ($time<>''&&isset($time) and $time1<>''&&isset($time1)) $where['addtime']=$time;
        if ($time<>''&&isset($time) and $time1<>''&&isset($time1)) $where['addtime']=$time1;
        if ($price<>''&&isset($price) and $price1<>''&&isset($price1)) $where['price']=$price;
        if ($price<>''&&isset($price) and $price1<>''&&isset($price1)) $where['price']=$price1;

        $parent=\app\index\model\category::category();
        $list=\app\index\model\goods::goodList($where);
        View::assign('list',$list);
        View::assign('parent',$parent);
        return View::fetch('goods/good_list');
    }

    public function brand()
    {
        $where=[];
        $show=Request::param('if_show');
        $recommended=Request::param('recommended');
        $keywords=Request::param('keywords');
        $img1=Request::param('img1');
        $img=Request::param('img');
        if ($show<>''&&isset($show)) $where['if_show']=$show;
        if ($recommended<>''&&isset($recommended)) $where['recommended']=$recommended;
        if ($keywords<>''&&isset($keywords)) $where['keywords']=$keywords;
        if ($img1<>''&&isset($img1)) $where['img1']='';
        if ($img<>''&&isset($img)) $where['img']='';
        $brand=\app\index\model\brand::brand($where);
        View::assign('brand',$brand);
        return View::fetch('goods/brand');
    }
    public function goodAdd()
    {
        return View::fetch('goods/good_add');
    }
    public function cate()
    {
        $pid=Request::param('parentid',0);
//        foreach ($cate as &$v){
//            $v['next']=\think\facade\Db::table('ecm_category')
//                ->where('parentid',$v['id'])
//                ->count();
//        }
        //缓存has get  set
        //判断缓存是否设置

        $cate1=\app\index\model\category::cate1();
        $cate=\app\index\model\category::cate($pid);
        View::assign('cate',$cate);
        View::assign('cate1',$cate1);
        return View::fetch('goods/cate');
    }
    public function cateEdit()
    {
        return View::fetch('goods/cateedit');
    }
}